<?php
session_start();
header('Content-Type:text/html;charset=utf-8');
$account=$_POST['account'];
$pwd=$_POST['pwd'];
$pwd1=$_POST['pwd1'];
$pname=$_POST['pname'];
$email=$_POST['email'];
$yzm=$_POST['yzm'];
$cyzm=$_COOKIE['yzm'];
require_once($_SERVER['DOCUMENT_ROOT'].'/public/func.php');
$config=require_once($_SERVER['DOCUMENT_ROOT'].'/public/config.php');
$arrac=selects($config,'vip',"where `account`='$account'");
$arrpn=selects($config,'vip',"where `pname`='$pname'");
$arrem=selects($config,'vip',"where `email`='$email'");
$pattern='/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/';
$pattern1='/^[a-zA-Z0-9_]{6,16}$/';
if(!strcasecmp($yzm,$cyzm)=='0'){
   //var_dump(strcasecmp($yzm,$cyzm));die;
    echo  "<script>alert('验证码输入错误');window.location.href='/home/landing/registered/registered.php'</script>";
}else{
    setcookie('yzm','');
}
if($pname==''){
        echo  "<script>alert('昵称不能为空');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($account==''){
       echo  "<script>alert('账号不能为空');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($pwd==''){
      echo  "<script>alert('密码不能为空');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($pwd!=$pwd1){
    echo  "<script>alert('两次输入密码不一致');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($arrac){
    echo  "<script>alert('此账号已经被注册');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($arrpn){
    echo  "<script>alert('此昵称已经被注册');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif(!preg_match($pattern,$email)){
    echo  "<script>alert('邮箱格式不正确');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif(!preg_match($pattern1,$account)){
    echo  "<script>alert('账号格式不正确');window.location.href='/home/landing/registered/registered.php'</script>";
}elseif($arrem){
    echo  "<script>alert('该邮箱已被注册');window.location.href='/home/landing/registered/registered.php'</script>";
}else{
    $_POST['mfile']=up('mfile');
    $arr=array('account'=>$_POST['account'],'pwd'=>$_POST['pwd'],'pname'=>$_POST['pname'],'email'=>$_POST['email'],'mfile'=>$_POST['mfile']);
    $rec=add($config,'vip',$arr);
    if($rec){
         $_SESSION['vip']['account']=$account;
         $_SESSION['vip']['pname']=$pname;
         $_SESSION['vip']['email']=$email;
         setcookie("islogin",'1',time()+60);
         echo  "<script>window.location.href='/home/landing/registered/finish.php'</script>";
    }
    echo "<script>alert('注册失败');window.location.href='/home/landing/registered/registered.php'</script>";
}
?>